//
// Created by 25137 on 2024/2/6.
//

#ifndef BOOST_ASIO_MSERIALPORT_H
#define BOOST_ASIO_MSERIALPORT_H

#include <asio.hpp>
#include <memory>
#include <list>
#include <string>
#include <utility>
#include "mport.h"
using namespace asio;
using std::list;
using std::unique_ptr;
class COM_PORT {
public:
    COM_PORT(std::string name):io(std::make_shared<io_service>()){
        port = std::make_unique<MPort>(*(io.get()),name);

    };
public:
    shared_ptr<io_service> io;
    unique_ptr<MPort> port;
};
class MSerialPort {
public:
    list<MPort::COM_Info> ALLCOM;
public:
    MSerialPort();
    ~MSerialPort();
    void scanCOM();
    MPort::COM_STATUS openCOM(const std::function<void(MIODeviceBase)>& callback,const std::string&, int baud = 115200);
//    bool isOpen();
    MPort::COM_STATUS closeCOM(const std::string &name);
private:

   unique_ptr< list< unique_ptr<COM_PORT>>> COM_list;
};


#endif //BOOST_ASIO_MSERIALPORT_H
